package chapter2.observerMode.observer.impl;

import chapter2.observerMode.observable.Observable;
import chapter2.observerMode.observer.Observer;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class FullTimePlate implements Observer {
    private LocalDateTime dateTime;
    private Observable observable;

    public FullTimePlate(Observable observable){
        this.observable = observable;
        this.observable.addObserver(this);
    }

    @Override
    public void update(Object obj) {
        if(obj instanceof LocalDateTime){
            this.dateTime = (LocalDateTime)obj;
        }else{
            this.dateTime = LocalDateTime.now();
        }
        display();
    }

    public void display(){
        System.out.printf("现在是北京时间%s\n", dateTime.format(DateTimeFormatter.ISO_DATE_TIME));
    }
}
